﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>客户注册</title>

    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />


    <script src="../JS/layer/layer.m.js"></script>
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>
    <script>
        //document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        //    //隐藏右上角按钮
        //    WeixinJSBridge.call('hideOptionMenu');
        //});

        //MobileCom.delCookie("szhlcode");
        //if (MobileCom.getCookie("szhlcode") == null) {
        //    MobileCom.setCookie("szhlcode", "aeac70cc-c359-45f2-90ac-78cb7abe5816", 7);
        //}

        var height = 0;
        var model = avalon.define({
            $id: "kfmodel",
            ctData: { "UserName": "", "UserRealName": "", "UserPass": "123", "IsUse": "Y", "zhiwu": "", "mobphone": "", "mailbox": "", "Usersign": "", "BranchName": "", "BranchCode": "" },
            savedata: function () {
                if (!model.ctData.mobphone) {
                    $.tips({
                        content: "请输入手机号",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                else {
                    var reg2 = /^(?:13\d|14\d|15\d|17\d|18\d)-?\d{5}(\d{3}|\*{3})$/;
                    if (!reg2.test(model.ctData.mobphone)) {
                        $.tips({
                            content: "手机号格式错误",
                            stayTime: 2000,
                            type: "warn"
                        })
                        return;
                    }
                    else {
                        model.ctData.UserName = model.ctData.mobphone;
                    }
                }

                if (!model.ctData.UserPass ) {
                    $.tips({
                        content: "请输入客户密码",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (!model.ctData.UserRealName) {
                    $.tips({
                        content: "请输入真实姓名",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                
                
                //if (!model.ctData.mailbox) {
                //    $.tips({
                //        content: "请输入邮箱地址",
                //        stayTime: 2000,
                //        type: "warn"
                //    })
                //    return;
                //}
                //else {
                //    var reg3 = /^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/;
                //    if (!reg3.test(model.ctData.mailbox)) {
                //        $.tips({
                //            content: "邮箱地址格式错误",
                //            stayTime: 2000,
                //            type: "warn"
                //        })
                //        return;
                //    }
                //}

                if (!model.ctData.Usersign) {
                    $.tips({
                        content: "请输入公司名称",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }

                var lg = $.loading({
                    content: '保存中...',
                })
                $.post("/API/SZHLAPI.ashx?Action=ADDKFUSER&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model) }, function (data) {
                    lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $("button").hide();
                        var el = $.tips({
                            content: "保存成功！！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {
                            window.location.replace("UI_QRCODE.html?r=" + Math.random());
                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                    }
                })
            }

        });

        avalon.ready(function () {

            var lg = $.loading({
                content: '加载中...'
            })
            $.getJSON("/API/SZHLAPI.ashx?action=GETKFBRANCH&r=" + Math.random(), {}, function (r) {
                if (r.ErrorMsg == "") {
                    if (r.Result) {
                        model.ctData.BranchCode = r.Result.DeptCode;
                        model.ctData.BranchName = r.Result.DeptName;
                        $.getJSON("/API/SZHLAPI.ashx?action=GETKFROLE&r=" + Math.random(), {}, function (r) {
                            lg.hide();
                            if (r.ErrorMsg == "") {
                                if (r.Result) {
                                    model.ctData.zhiwu = r.Result.RoleName;
                                }
                                else {
                                    $.tips({
                                        content: "无客户角色",
                                        stayTime: 2000,
                                        type: "warn"
                                    })
                                }
                            }
                        })
                    }
                    else {
                        lg.hide();
                        $.tips({
                            content: "无客户部门",
                            stayTime: 2000,
                            type: "warn"
                        })
                    }
                }
                else {
                    lg.hide();
                }
            })
        })

        function back() {
            window.location.replace("UI_KHGL_LIST.html?r=" + Math.random());
        }
    </script>

    <style type="text/css">
        .ui-select {
            border: none;
            border: 0;
            background-color: #fff;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }
        .ui-form-item .wspan {
            width: 100%;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }

        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>

</head>
<body ms-controller="kfmodel">
    <div style="height:1px;overflow:hidden;">
        <img src="../Images/logo.jpg" />
    </div>
    <div id="content">

        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">

            <button class="ui-btn-lg ui-btn-primary" ms-click="savedata()" id="save">
                客户注册
            </button>
        </div>
        <section class="ui-container">
            <div class="ui-form ui-border-t">
                <!--<div class="ui-form-item ui-border-b">
                    <label>
                        所属部门
                    </label>
                    <span class="wspan">{{ctData.BranchName}}</span>
                </div>-->
                <div class="ui-form-item ui-border-b">
                    <label>
                        手机号
                    </label>
                    <input type="tel" placeholder="请输入手机号" ms-duplex="ctData.mobphone" />
                </div>
                <div class="ui-form-item ui-border-b ">
                    <label>
                        真实姓名
                    </label>
                    <input type="text" placeholder="请输入真实姓名" ms-duplex="ctData.UserRealName" />
                </div>
                <!--<div class="ui-form-item ui-border-b ">
                    <label>
                        客户密码
                    </label>
                    <input type="password" placeholder="请输入客户密码" ms-duplex="ctData.UserPass" />
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        是否可用
                    </label>
                    <label class="ui-switch" style="padding-left: 95px;right:auto">
                        <input type="checkbox" ms-duplex-radio="ctData.IsUse" />
                    </label>
                </div>

                <div class="ui-form-item ui-border-b">
                    <label>
                        职务
                    </label>
                    <span class="wspan">{{ctData.zhiwu}}</span>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        手机号
                    </label>
                    <input type="tel" placeholder="请输入手机号" ms-duplex="ctData.mobphone" />

                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        邮箱地址
                    </label>
                    <input type="text" placeholder="请输入邮箱地址" ms-duplex="ctData.mailbox" />
                </div>-->
                <div class="ui-form-item ui-border-b">
                    <label>
                        公司名称
                    </label>
                    <input type="text" placeholder="请输入公司名称" ms-duplex="ctData.Usersign" />
                </div>
            </div>
        </section>
    </div>

</body>

</html>

